/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BAReservationReadyForPickupCell.m
//  redia-bapps-ios
//
//  Created by Brian Vestergaard Danielsen on 10/7/13.
//  Copyright (c) 2013 Redia A/S. All rights reserved.
//

#import "BAReservationReadyForPickupCell.h"
#import "BAUtils.h"
#import "BALibrarySettings.h"

@implementation BAReservationReadyForPickupCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib
{
    BA_LABEL_SET_FONT_LIGHT(self.pickupDueDateDayLabel);
    BA_LABEL_SET_FONT_LIGHT(self.pickupDueDateMonthLabel);
    BA_LABEL_SET_FONT_LIGHT(self.titleLabel);
    self.viewLeftCustomColor.backgroundColor = [[BALibrarySettings instance] getCustomerColorNormal];
    
}

- (void)setReservation:(BAReservation*)reservation {
    if(reservation.pickUpNo != nil) {
        self.pickupNumberLabel.text = reservation.pickUpNo;
    }
    
    if(reservation.pickUpBranch != nil) {
        self.pickUpBranchLabel.text = reservation.pickUpBranch;
    }
    
    NSString* titlestring = [NSString stringWithFormat:@"%@%@%@",
                             reservation.title,
                             ([reservation.title length]>0 && [reservation.note length]>0) ? @", " : @"",
                             reservation.note
                             ];

    self.titleLabel.text = titlestring;
    
    NSString* branchName = [self.parentReservationsController.branchesDictionary objectForKey:reservation.pickUpBranch];
    self.pickUpBranchLabel.text = branchName;
    
    NSDate* pickupExpireDate = [NSDate dateWithTimeIntervalSince1970:reservation.pickUpExpireDate];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"da_DK"]];
    
    // day
    [dateFormatter setDateFormat:@"dd"];
    NSString* day = [NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:pickupExpireDate]];
    NSString *paddedStr = [NSString stringWithFormat:@"%02d", [day intValue]];
    self.pickupDueDateDayLabel.text = paddedStr;
    
    [dateFormatter setDateFormat:@"MMM"];
    NSString* month = [NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:pickupExpireDate]];
    self.pickupDueDateMonthLabel.text = [month uppercaseString];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
